package com.stormrage.shiro.filter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;
import org.springframework.beans.factory.annotation.Autowired;

import com.stormrage.constants.Constants;
import com.stormrage.edu.serv.shiro.ShiroServ;

/**
 * @author www.stormragetech.com
 * @date 2016年1月19日
 * @version 1.0.0
 */
public class SysUserFilter extends PathMatchingFilter {

	@Autowired
	private ShiroServ shiroServ;

	@Override
	protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue)
			throws Exception {

		String acct = (String) SecurityUtils.getSubject().getPrincipal();
		request.setAttribute(Constants.CURRENT_USER, shiroServ.queryAcctByAcct(acct));
		return true;
	}
}
